package com.erp.app.common.util;

import java.sql.Connection;
import java.util.ArrayList;

import com.erp.framework.exceptions.DbObjectException;
import com.erp.framework.model.vo.SimpleBaseVo;
import com.erp.framework.util.DbObjectUtil;
import com.erp.framework.util.logger.Logger;

public class ProjectDbObjectUtil extends DbObjectUtil {
	
	/**
	 * Please only put common functions in this class, i.e. a function that is
	 * shared among 2 or more different MODULES.
	 * 
	 * If only one function for one module, please define the function in the
	 * specific module DAO class.
	 */
	
	
	//The following is for SO/PO/Invoice/etc dtl amt sum up to hdr amt
	public void calcAmounts(SimpleBaseVo model, Connection conn, String docType) throws Exception {
		String spName = "sp_cal_doc_amounts";
		ArrayList args = new ArrayList();
		try {
			
			super.callSp(spName, args, conn);
		} catch (Exception e) {
			// The following exceptions is used to capture all Stored Proc,
			// Functions, View, Trigger, Sequence, etc
			Logger.logExceptions(this, e);
			throw new DbObjectException(e.getMessage());
		}
	}

	//the following is for SO/PO/Invoice/etc calc item task dates
	public void calcItemTaskDates(SimpleBaseVo model, Connection conn, String docType) throws Exception {
		String spName = "sp_update_task_dates";
		ArrayList args = new ArrayList();
		
		try {			
			
			super.callSp(spName, args, conn);
		} catch (Exception e) {
			Logger.logExceptions(this, e);
			throw new DbObjectException(e.getMessage());
		}
	}
	
	//the following is for SO to create item customers
	public void createItemCustomer(SimpleBaseVo model, Connection conn, String docType) throws Exception {
		String spName = "sp_create_item_cust";
		ArrayList args = new ArrayList();
		
		try {			
			
			super.callSp(spName, args, conn);
		} catch (Exception e) {
			Logger.logExceptions(this, e);
			throw new DbObjectException(e.getMessage());
		}
	}
	
	//the following is for SO to create item customers
	public void genDnFromInvoice(String companyCode, String invoiceNo, String userId,
			Connection conn) throws Exception {
		try {			
			ArrayList args = new ArrayList();
		        args.add(companyCode);
		        args.add(invoiceNo);
		        args.add(userId);
		        System.out.println(args);
			super.callSp("sp_gen_dn_from_invoice", args, conn);
		} catch (Exception e) {
			Logger.logExceptions(this, e);
			throw new DbObjectException(e.getMessage());
		}
	}

	//The following is for SO/PO/Invoice/etc dtl amt sum up to hdr amt
//	public void calcAmounts(ArrayList args, Connection conn) throws Exception {
//		//String query = "{ call sp_cal_doc_amounts(?,?,?,?) }";
//		String spName = "sp_cal_doc_amounts";
//		try {
//			super.callSp(spName, args, conn);
//		} catch (Exception e) {
//			// The following exceptions is used to capture all Stored Proc,
//			// Functions, View, Trigger, Sequence, etc
//			throw new DbObjectException(e.getMessage());
//		}
//	}

}
